from flask import request
from flask.views import MethodView

from qingdeng.orms import UserORM


class UserAPI(MethodView):
    def get(self, user_id):
        # 翻页查询
        page = request.args.get("page", default=1, type=int)
        per_page = request.args.get("per_page", default=10, type=int)

        filters = []

        paginate = (
            UserORM.query.order_by(UserORM.create_time.asc())
            .filter(*filters)
            .paginate(page=page, per_page=per_page, error_out=False)
        )

        # 接口只返回数据,不返回模板
        user_list = [user.json() for user in paginate.items]
        return {"code": 0, "msg": "获取数据成功", "count": paginate.total, "data": user_list}

    def post(self):
        pass

    def put(self, user_id):
        pass

    def delete(self, user_id):
        pass
